package hc.uco

import java.util.Date;

class HistoriaPregressa {

	Paciente paciente
	static belongsTo = [paciente:Paciente]
	
	static transients = [ "macosAno" ]
	
	Boolean iam
	Date iamData1
	Date iamData2
	Date iamData3
	
	Boolean angioplastia
	Boolean angioplastia2
	Boolean angioplastia3
	Boolean angioplastia4
	Boolean angioplastia5
	Date angioplastiaData1
	Boolean stent1
	String stentTipo1
	String stentPrimEle1
	Date angioplastiaData2
	Boolean stent2
	String stentTipo2
	String stentPrimEle2
	Date angioplastiaData3
	Boolean stent3
	String stentTipo3
	String stentPrimEle3
	Date angioplastiaData4
	Boolean stent4
	String stentTipo4
	String stentPrimEle4
	Date angioplastiaData5
	Boolean stent5
	String stentTipo5
	String stentPrimEle5
	
	Boolean insuficienciaCardiaca
	String insuficienciaCardiacaTipo
	Integer insuficienciaCardiacaClasse
	
	Boolean anginaEstavel
	Integer anginaEstavelClasse
	
	Boolean cateEstenose
	Boolean dap 
	
	Boolean dmi
	Integer dmiAno
	Boolean dmii
	Integer dmiiAno
	Boolean has
	Integer hasAno
	Boolean chagas
	Integer chagasAno
	
	Boolean sedentarismo
	
	Boolean tabagista
	Integer numAno
	Integer macosDia
	Integer macosAno
	Boolean exTabagista
	Date dataParada

	Boolean histFamiliar //(AVC, IAM, MS)
	
	Boolean avc
	Date avcData1
	Date avcData2
	
	Boolean rvm
	Date rvmData
	String rvmEnxertos
	
	String outros
	
	
	//reperfusao
	Boolean tombolise
	Date tomboliseData
	String trombolitico
	String tromboliticoDose
	Boolean tromboliticoSucesso
	Boolean atc
	Date atcData
	Integer deltaT
	Boolean atcComplementar
	Date atcDataComplementar
	String deltaTComplementar
	
	//ECG
	String ritmo
	String bloqueio
	Boolean alteracaoSupra
	String devivacaoSupra
	Boolean alteracaoInfra
	String devivacaoInfra
	Boolean alteracaoInversao
	String devivacaoInversao
	Boolean alteracaoDelta
	String devivacaoDelta
	
	Usuario createdBy
	Usuario updatedBy
	Date dateCreated
	Date lastUpdated
	
	static arterias = ["DA", "DG1", "DG2","DG3","DGLIS","CX","DP (CX)","VP (CX)", "CD", "DP (CD)", "VP (CD)", "MG1","MG2","MG3"];
	
    static constraints = {
		iamData1(nullable:true,	validator: { val, obj ->
				if(obj.properties['iam'] && val == null) return ['default.blank.message']
				if(!obj.properties['iam']) obj.properties['iamData1'] = null })
		iamData2(nullable:true, validator: { val, obj ->
				if(obj.properties['iamData1'] == null && val != null )  { obj.properties['iamData2'] = null; return ['historiaPregressa.iamData1.blank']}
				if(!obj.properties['iam']) obj.properties['iamData2'] = null } )
		iamData3(nullable:true,	validator: { val, obj ->
				if(obj.properties['iamData2'] == null  && val != null )   return ['blank']
				if(!obj.properties['iam']) obj.properties['iamData3'] = null	 })
		
		
		angioplastiaData1(nullable:true, validator: { val, obj ->
			if(obj.properties['angioplastia'] && val == null) return ['default.blank.message']
			if(!obj.properties['angioplastia']) obj.properties['angioplastiaData1'] = null })
		stentTipo1(nullable:true, blank:true, 
			validator: { val, obj ->
			if(obj.properties['stent1'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent1']) obj.properties['stentTipo1'] = null })
		stentPrimEle1(nullable:true, blank:true, inList:["Primária", "Eletiva"], validator: { val, obj ->
			if(obj.properties['stent1'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent1']) obj.properties['stentPrimEle1'] = null })
		
		angioplastiaData2(nullable:true, validator: { val, obj ->
			//if(obj.properties['angioplastia'] && val == null) return ['blank']
			if(!obj.properties['angioplastia']) obj.properties['angioplastiaData2'] = null })
		stentTipo2(nullable:true, blank:true, validator: { val, obj ->
			if(obj.properties['stent2'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent2']) obj.properties['stentTipo2'] = null })
		stentPrimEle2(nullable:true, blank:true, inList:["Primária", "Eletiva"], validator: { val, obj ->
			if(obj.properties['stent2'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent2']) obj.properties['stentPrimEle2'] = null })
		
		angioplastiaData3(nullable:true, validator: { val, obj ->
			//if(obj.properties['angioplastia'] && val == null) return ['blank']
			if(!obj.properties['angioplastia']) obj.properties['angioplastiaData3'] = null })
		stentTipo3(nullable:true, blank:true, validator: { val, obj ->
			if(obj.properties['stent3'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent3']) obj.properties['stentTipo3'] = null })
		stentPrimEle3(nullable:true, blank:true, inList:["Primária", "Eletiva"], validator: { val, obj ->
			if(obj.properties['stent3'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent3']) obj.properties['stentPrimEle3'] = null })
		
		angioplastiaData4(nullable:true, validator: { val, obj ->
			//if(obj.properties['angioplastia'] && val == null) return ['blank']
			if(!obj.properties['angioplastia']) obj.properties['angioplastiaData4'] = null })
		stentTipo4(nullable:true, blank:true, validator: { val, obj ->
			if(obj.properties['stent4'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent4']) obj.properties['stentTipo4'] = null })
		stentPrimEle4(nullable:true, blank:true, inList:["Primária", "Eletiva"], validator: { val, obj ->
			if(obj.properties['stent4'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent4']) obj.properties['stentPrimEle4'] = null })
		
		angioplastiaData5(nullable:true, validator: { val, obj ->
			//if(obj.properties['angioplastia'] && val == null) return ['blank']
			if(!obj.properties['angioplastia']) obj.properties['angioplastiaData5'] = null })
		stentTipo5(nullable:true, blank:true, validator: { val, obj ->
			if(obj.properties['stent5'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent5']) obj.properties['stentTipo5'] = null })
		stentPrimEle5(nullable:true, blank:true, inList:["Primária", "Eletiva"], validator: { val, obj ->
			if(obj.properties['stent5'] && val == null) return ['default.blank.message']
			if(!obj.properties['stent5']) obj.properties['stentPrimEle5'] = null })
		
		insuficienciaCardiacaTipo(nullable:true, blank:true, inList:["Sistólica", "Diastólica"], validator: { val, obj ->
			if(obj.properties['insuficienciaCardiaca'] && val == null) return ['default.blank.message']
			if(!obj.properties['insuficienciaCardiaca']) obj.properties['insuficienciaCardiacaTipo'] = null })
		insuficienciaCardiacaClasse(nullable:true, blank:true, inList:[1,2,3,4], validator: { val, obj ->
		    if(obj.properties['insuficienciaCardiaca'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['insuficienciaCardiaca']) obj.properties['insuficienciaCardiacaClasse'] = null } )
		anginaEstavelClasse(nullable:true, blank:true, inList:[1,2,3,4], validator: { val, obj ->
			if(obj.properties['anginaEstavel'] && val < 1) return ['default.blank.message']
			if(!obj.properties['anginaEstavel']) obj.properties['anginaEstavelClasse'] = null } )
		dmiAno(nullable:true, range:1900..2050, validator: { val, obj ->
		    if(obj.properties['dmi'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['dmi']) obj.properties['dmiAno'] = null })
		dmiiAno(nullable:true, range:1900..2050, validator: { val, obj ->
		    if(obj.properties['dmii'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['dmii']) obj.properties['dmiiAno'] = null })
		hasAno(nullable:true, range:1900..2050, validator: { val, obj ->
		    if(obj.properties['has'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['has']) obj.properties['hasAno'] = null })
		chagasAno(nullable:true, range:1900..2050, validator: { val, obj ->
		    if(obj.properties['chagas'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['chagas']) obj.properties['chagasAno'] = null })
		
		avcData1(nullable:true, validator: { val, obj ->
		    if(obj.properties['avc'] && val == null) return ['default.blank.message']
		    if(!obj.properties['avc']) obj.properties['avcData1'] = null })
		avcData2(nullable:true, validator: { val, obj ->
		    //if(obj.properties['avc'] && val == null) return ['default.blank.message']
		    if(!obj.properties['avc']) obj.properties['avcData2'] = null })
		
		numAno(nullable:true, validator: { val, obj ->
		    if(obj.properties['tabagista'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['tabagista']) obj.properties['numAno'] = null })
		macosDia(nullable:true, validator: { val, obj ->
		    if(obj.properties['tabagista'] && val < 1) return ['default.blank.message']
		    if(!obj.properties['tabagista']) obj.properties['macosDia'] = null })
		dataParada(nullable:true, validator: { val, obj ->
		    if(obj.properties['exTabagista'] && val == null) return ['default.blank.message']
		    if(!obj.properties['exTabagista']) obj.properties['dataParada'] = null })
		rvmData(nullable:true, validator: { val, obj ->
		    if(obj.properties['rvm'] && val == null) return ['default.blank.message']
		    if(!obj.properties['rvm']) obj.properties['rvmData'] = null })
		rvmEnxertos(nullable:true, validator: { val, obj ->
		    if(obj.properties['rvm'] && val == null) return ['default.blank.message']
		    if(!obj.properties['rvm']) obj.properties['rvmEnxertos'] = null })
		outros(nullable:true, maxSize: 800)
		
		tomboliseData(nullable:true, validator: { val, obj ->
		    if(obj.properties['tombolise'] && val == null) return ['default.blank.message']
		    if(!obj.properties['tombolise']) obj.properties['tomboliseData'] = null })
		trombolitico(nullable:true, inList:["Alteplase (RTTA)", "Estreptoquinase (SK)", "Tenecteplase (TNK)"], validator: { val, obj ->
			if(obj.properties['tombolise'] && val == null) return ['default.blank.message']
			if(!obj.properties['tombolise']) obj.properties['trombolitico'] = null })
		tromboliticoDose(nullable:true, validator: { val, obj ->
			if(obj.properties['tombolise'] && val == null) return ['default.blank.message']
			if(!obj.properties['tombolise']) obj.properties['tromboliticoDose'] = null })
		tromboliticoSucesso(nullable:true, validator: { val, obj ->
			if(obj.properties['tombolise'] && val == null) return ['default.blank.message']
			if(!obj.properties['tombolise']) obj.properties['tromboliticoSucesso'] = null })
		atcData(nullable:true, validator: { val, obj ->
		    if(obj.properties['atc'] && val == null) return ['default.blank.message']
		    if(!obj.properties['atc']) obj.properties['atcData'] = null })
		deltaT(nullable:true, validator: { val, obj ->
		    if(obj.properties['atc'] && val == null) return ['default.blank.message']
		    if(!obj.properties['atc']) obj.properties['deltaT'] = null })
		atcDataComplementar(nullable:true, validator: { val, obj ->
			if(obj.properties['atcComplementar'] && val == null) return ['default.blank.message']
			if(!obj.properties['atcComplementar']) obj.properties['atcDataComplementar'] = null })
		deltaTComplementar(nullable:true, validator: { val, obj ->
			if(obj.properties['atcComplementar'] && val == null) return ['default.blank.message']
			if(!obj.properties['atcComplementar']) obj.properties['deltaTComplementar'] = null })
		
		ritmo(nullable:true, blank:true, inList:["Sinusal", "Fibrilação Atrial", "Outro"])
		bloqueio(nullable:true, blank:true, inList:["De ramo Direto", "De ramo Esquerdo", "Intraventricular"])
		
		
		devivacaoSupra(nullable:true, validator: { val, obj ->
			if(obj.properties['alteracaoSupra'] && val == null) return ['default.blank.message']
			if(!obj.properties['alteracaoSupra']) obj.properties['devivacaoSupra'] = null })
		devivacaoInfra(nullable:true, validator: { val, obj ->
			if(obj.properties['alteracaoInfra'] && val == null) return ['default.blank.message']
			if(!obj.properties['alteracaoInfra']) obj.properties['devivacaoInfra'] = null })
		devivacaoInversao(nullable:true, validator: { val, obj ->
			if(obj.properties['alteracaoInversao'] && val == null) return ['default.blank.message']
			if(!obj.properties['alteracaoInversao']) obj.properties['devivacaoInversao'] = null })
		devivacaoDelta(nullable:true, validator: { val, obj ->
			if(obj.properties['alteracaoDelta'] && val == null) return ['default.blank.message']
			if(!obj.properties['alteracaoDelta']) obj.properties['devivacaoDelta'] = null })
		
		
    }
	
	Integer getMacosAno() {
		if ( numAno != null && numAno > 0 && macosDia != null && macosDia > 0 ) {
			int ma = numAno * macosDia
			return ma
		}	else
			return null
	}
	
}
